var role = require("../lib/role");
module.exports = {
	prefix: "/admin_tag",
	get: {
		//分页返回用户自己的博文列表信息，包括分页信息
		"/list": function() {
			var admin = role.getAdmin(this);
			var tag_list = admin.getOpenTagList();
			this.body = ResponObj("json", tag_list);
		},
	},
	put: {
		"/update_tag": function() {
			var admin = role.getAdmin(this);
			var tag_info = this.request.body;
			var tag = admin.updateTag(tag_info._id, tag_info);
			this.body = ResponObj("json", tag);
		}
	},
	post: {
		"/add_tag": function() {
			var admin = role.getAdmin(this);
			var tag_info = this.request.body;
			var tag = admin.addOpenTag(tag_info);
			this.body = ResponObj("json", tag);
		}
	},
	delete: {
		"/delete_tag/:tag_id": function() {
			var admin = role.getAdmin(this);
			var tag_id = this.params.tag_id;
			var body = this.request.body;
			admin.removeTag(tag_id);
			if (body.back_list) { //以列表信息返回
				var tag_list_info = admin.getOpenTagList();
				this.body = ResponObj("json", tag_list_info);
			} else {
				this.body = ResponObj("string", "标签删除成功");
			}
		}
	}
}